"use strict";

var __extends = this && this.__extends || function() {
    var extendStatics = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(d, b) {
        d.__proto__ = b;
    } || function(d, b) {
        for (var p in b) b.hasOwnProperty(p) && (d[p] = b[p]);
    };
    return function(d, b) {
        function __() {
            this.constructor = d;
        }
        extendStatics(d, b), d.prototype = null === b ? Object.create(b) : (__.prototype = b.prototype, 
        new __());
    };
}(), powerbi;

!function(powerbi) {
    var visuals;
    !function(visuals) {
        var createClassAndSelector = jsCommon.CssConstants.createClassAndSelector, KeyUtils = jsCommon.KeyUtils, StringExtensions = jsCommon.StringExtensions, UrlScheme = jsCommon.UrlUtils.UrlScheme, UrlUtils = jsCommon.UrlUtils, Textbox = function() {
            function Textbox(options) {
                options && (options.viewModelAdapter && (this.viewModelAdapter = options.viewModelAdapter), 
                this.disableScrollingInViewMode = options.disableScrollingInViewMode);
            }
            return Textbox.prototype.init = function(options) {
                this.element = options.element, this.host = options.host, this.viewport = options.viewport, 
                this.readOnly = 0 === this.host.getViewMode(), this.paragraphs = [], this.refreshView();
            }, Textbox.prototype.onResizing = function(viewport) {
                var oldViewport = this.viewport;
                this.viewport = viewport, this.updateSize(), this.viewModelAdapter && this.viewModelAdapter.onResizing(this.element, this.viewport, oldViewport);
            }, Textbox.prototype.onDataChanged = function(options) {
                var dataViews = options.dataViews;
                if (this.paragraphs = [], dataViews && dataViews.length > 0) {
                    var objects = dataViews[0].metadata.objects;
                    objects && objects.general && (this.paragraphs = objects.general.paragraphs);
                }
                this.refreshView();
            }, Textbox.prototype.destroy = function() {}, Textbox.prototype.focus = function() {
                if (this.editor) return this.editor.focus(), !0;
            }, Textbox.prototype.onViewModeChanged = function(viewMode) {
                this.readOnly = 0 === viewMode, this.refreshView();
            }, Textbox.prototype.setSelection = function(index, length) {
                this.editor && this.editor.setSelection(index, length);
            }, Textbox.prototype.refreshView = function() {
                var _this = this;
                if (this.readOnly) {
                    this.editor && (this.saveContents(), this.editor.destroy(), this.editor = null), 
                    this.element.empty();
                    var htmlContent = RichTextConversion.convertParagraphsToHtml(this.paragraphs), textBox = $("<div>").addClass(Textbox.ClassAndSelector.class).css({
                        "font-family": RichText.defaultFont,
                        "font-size": RichText.defaultFontSize
                    }).append(htmlContent);
                    this.viewModelAdapter && this.viewModelAdapter.onDataChanged(textBox, this.viewport), 
                    this.disableScrollingInViewMode ? this.element.append(textBox) : (this.$scrollableDiv = $("<div/>").addClass(Textbox.ScrollWrapperClassAndSelector.class).css({
                        height: this.viewport.height + "px",
                        "overflow-y": "auto"
                    }).append(textBox), this.element.append(this.$scrollableDiv));
                } else {
                    if (!this.editor) {
                        this.editor = new RichText.QuillWrapper(this.readOnly, this.host), this.editor.textChanged = function() {
                            return _this.saveContents();
                        }, this.element.empty();
                        var editorElement = this.editor.getElement();
                        editorElement.addClass(Textbox.ClassAndSelector.class), editorElement.css({
                            "font-family": RichText.defaultFont,
                            "font-size": RichText.defaultFontSize
                        }), this.element.append(editorElement);
                    }
                    this.editor.setContents(RichTextConversion.convertParagraphsToOps(this.paragraphs));
                }
                this.updateSize();
            }, Textbox.prototype.saveContents = function() {
                if (this.editor) {
                    var contents = this.editor.getContents();
                    this.paragraphs = RichTextConversion.convertDeltaToParagraphs(contents);
                    var changes = [ {
                        objectName: "general",
                        properties: {
                            paragraphs: this.paragraphs
                        },
                        selector: null
                    } ];
                    this.host.persistProperties(changes);
                }
            }, Textbox.prototype.updateSize = function() {
                this.editor ? this.editor.resize(this.viewport) : this.$scrollableDiv && this.$scrollableDiv.css("height", this.viewport.height + "px");
            }, Textbox.ClassAndSelector = jsCommon.CssConstants.createClassAndSelector("textbox"), 
            Textbox.ScrollWrapperClassAndSelector = jsCommon.CssConstants.createClassAndSelector("scrollWrapper"), 
            Textbox;
        }();
        visuals.Textbox = Textbox;
        var TextboxHelpers;
        !function(TextboxHelpers) {
            var DefaultLinkInputValue = "http://", ViewModelAdapter = function() {
                function ViewModelAdapter(smallViewportProperties) {
                    this.smallViewportProperties = smallViewportProperties;
                }
                return ViewModelAdapter.prototype.onResizing = function(element, currentViewport, oldViewport) {
                    var wasPreviouslySmallViewport = this.isSmallViewport(oldViewport), isCurrentlySmallViewport = this.isSmallViewport(currentViewport);
                    wasPreviouslySmallViewport !== isCurrentlySmallViewport && this.applyScaleOnElement(element, isCurrentlySmallViewport);
                }, ViewModelAdapter.prototype.onDataChanged = function(element, viewport) {
                    this.isSmallViewport(viewport) && this.applyScaleOnElement(element, !0);
                }, ViewModelAdapter.prototype.isSmallViewport = function(viewport) {
                    return !!viewport && !!this.smallViewportProperties && (viewport.height <= this.smallViewportProperties.minHeightToScaleFontSize || viewport.width <= this.smallViewportProperties.minWidthToScaleFontSize);
                }, ViewModelAdapter.prototype.applyScaleOnElement = function(element, enableScale) {
                    element.find(Textbox.ClassAndSelector.selector).css({
                        "font-size": enableScale ? ViewModelAdapter.scale(RichText.defaultFontSize) : RichText.defaultFontSize
                    }), element.find(RichTextConversion.TextRunElement.selector).each(function(i, elm) {
                        var newFontSize, oldFontSize = $(elm).css("font-size") || RichText.defaultFontSize;
                        if (enableScale) newFontSize = ViewModelAdapter.scale(oldFontSize); else {
                            var textRunObj = $(elm).data(RichTextConversion.ModelKeyName);
                            newFontSize = textRunObj.textStyle && textRunObj.textStyle.fontSize ? textRunObj.textStyle.fontSize : RichText.defaultFontSize;
                        }
                        $(elm).css({
                            "font-size": RichText.getCssFontSize(newFontSize)
                        });
                    });
                }, ViewModelAdapter.scale = function(originFontSize) {
                    var scaled, size = parseInt(originFontSize.slice(0, -2), 10);
                    return scaled = size > 66 ? 32 : size > 42 ? 28 : size > 26 ? 24 : size > 16 ? 20 : size > 11 ? 14 : 12, 
                    jsCommon.PixelConverter.toString(scaled);
                }, ViewModelAdapter;
            }();
            TextboxHelpers.ViewModelAdapter = ViewModelAdapter;
            var AlwaysUseSmallViewport = function(_super) {
                function AlwaysUseSmallViewport() {
                    return _super.call(this, {
                        minHeightToScaleFontSize: 1 / 0,
                        minWidthToScaleFontSize: 1 / 0
                    }) || this;
                }
                return __extends(AlwaysUseSmallViewport, _super), AlwaysUseSmallViewport;
            }(ViewModelAdapter);
            TextboxHelpers.AlwaysUseSmallViewport = AlwaysUseSmallViewport;
            var LinkPreview = function() {
                function LinkPreview() {}
                return LinkPreview.format = function(preview) {
                    return /^\S+@\S+\.\S+$/.test(preview) ? "mailto:" + preview : /^https?:\/\//i.test(preview) ? preview : DefaultLinkInputValue + preview;
                }, LinkPreview;
            }();
            TextboxHelpers.LinkPreview = LinkPreview;
        }(TextboxHelpers = visuals.TextboxHelpers || (visuals.TextboxHelpers = {}));
        var RichTextConversion;
        !function(RichTextConversion) {
            function convertDeltaToParagraphs(contents) {
                for (var paragraphs = [], paragraph = {
                    textRuns: []
                }, i = 0, len = contents.ops.length; i < len; i++) {
                    var insertOp = contents.ops[i];
                    if ("string" == typeof insertOp.insert) {
                        var text = insertOp.insert, attributes = insertOp.attributes;
                        attributes && attributes.align && (paragraph.horizontalTextAlignment = attributes.align);
                        var start = 0, end = 0, newParagraph = void 0;
                        do {
                            if (end = text.indexOf("\n", start), end < 0 ? (newParagraph = !1, end = text.length) : newParagraph = !0, 
                            end - start > 0) {
                                var span = text.substring(start, end), textRun = {
                                    value: span
                                };
                                if (attributes) {
                                    void 0 !== attributes.link && isValidLinkUrl(attributes.link) && (textRun.url = attributes.link);
                                    var textStyle = convertFormatAttributesToTextStyle(attributes);
                                    textStyle && (textRun.textStyle = textStyle);
                                }
                                paragraph.textRuns.push(textRun);
                            }
                            newParagraph && (0 === paragraph.textRuns.length && paragraph.textRuns.push({
                                value: ""
                            }), paragraphs.push(paragraph), paragraph = {
                                textRuns: []
                            }), start = end + 1;
                        } while (start < text.length);
                    }
                }
                return paragraph.textRuns.length > 0 && paragraph.textRuns[0].value.length > 0 && paragraphs.push(paragraph), 
                paragraphs;
            }
            function convertParagraphsToHtml(paragraphs) {
                for (var $paragraphs = $(), paragraphIndex = 0, len = paragraphs.length; paragraphIndex < len; ++paragraphIndex) {
                    var paragraphDef = paragraphs[paragraphIndex], isParagraphEmpty = !0, $paragraph = $("<p>").data(RichTextConversion.ModelKeyName, paragraphDef);
                    paragraphDef.horizontalTextAlignment && $paragraph.css("text-align", paragraphDef.horizontalTextAlignment);
                    for (var textRunIndex = 0, jlen = paragraphDef.textRuns.length; textRunIndex < jlen; ++textRunIndex) {
                        var textRunDef = paragraphDef.textRuns[textRunIndex], $textRun = void 0, text = textRunDef.value;
                        _.isEmpty(text) || (isParagraphEmpty = !1), $textRun = void 0 !== textRunDef.url && isValidLinkUrl(textRunDef.url) ? $("<a>").attr("href", textRunDef.url).attr("rel", "noopener noreferrer").attr("target", "_blank") : $("<span>"), 
                        $textRun.text(text).addClass(RichTextConversion.TextRunElement.class).data(RichTextConversion.ModelKeyName, textRunDef);
                        var styleDef = textRunDef.textStyle;
                        if (styleDef) {
                            var css = {};
                            styleDef.fontFamily && (css["font-family"] = RichText.getCssFontFamily(styleDef.fontFamily)), 
                            styleDef.fontSize && (css["font-size"] = RichText.getCssFontSize(styleDef.fontSize)), 
                            styleDef.fontStyle && (css["font-style"] = styleDef.fontStyle), styleDef.fontWeight && (css["font-weight"] = styleDef.fontWeight), 
                            styleDef.color && (css.color = styleDef.color), styleDef.textDecoration && (css["text-decoration"] = styleDef.textDecoration), 
                            $textRun.css(css);
                        }
                        $paragraph.append($textRun);
                    }
                    isParagraphEmpty && $paragraph.append($("<br>")), $paragraphs = $paragraphs.add($paragraph);
                }
                return $paragraphs;
            }
            function convertParagraphsToOps(paragraphs) {
                for (var ops = [], paragraphIndex = 0, len = paragraphs.length; paragraphIndex < len; ++paragraphIndex) for (var paragraphDef = paragraphs[paragraphIndex], textRunIndex = 0, jlen = paragraphDef.textRuns.length; textRunIndex < jlen; ++textRunIndex) {
                    var textRunDef = paragraphDef.textRuns[textRunIndex], formats = {};
                    paragraphDef.horizontalTextAlignment && (formats.align = paragraphDef.horizontalTextAlignment);
                    var styleDef = textRunDef.textStyle;
                    styleDef && (styleDef.fontFamily && (formats.font = visuals.Font.normalizeFamily(RichText.getCssFontFamily(removeQuotes(styleDef.fontFamily)))), 
                    styleDef.fontSize && (formats.size = styleDef.fontSize), styleDef.color && (formats.color = styleDef.color), 
                    formats.italic = "italic" === styleDef.fontStyle || void 0, formats.bold = "bold" === styleDef.fontWeight || void 0, 
                    formats.underline = "underline" === styleDef.textDecoration || void 0);
                    var text = textRunDef.value;
                    textRunDef.url && isValidLinkUrl(textRunDef.url) && (formats.link = textRunDef.url);
                    var op = {
                        insert: text,
                        attributes: formats
                    };
                    ops.push(op), textRunIndex !== jlen - 1 || _.endsWith(text, "\n") || ops.push({
                        insert: "\n",
                        attributes: formats
                    });
                }
                return ops;
            }
            function isValidLinkUrl(value) {
                if (_.isEmpty(value)) return !1;
                switch (UrlUtils.getUrlScheme(value)) {
                  case UrlScheme.http:
                  case UrlScheme.https:
                  case UrlScheme.mailto:
                    return !0;

                  default:
                    return !1;
                }
            }
            function convertFormatAttributesToTextStyle(attributes) {
                var style = {};
                if (attributes.bold && (style.fontWeight = "bold"), attributes.font) {
                    var font = visuals.Font.normalizeFamily(_.unescape(attributes.font), !1);
                    font = RichText.getFontFamilyForBuiltInFont(font), style.fontFamily = font;
                }
                return attributes.italic && (style.fontStyle = "italic"), attributes.size && (style.fontSize = attributes.size), 
                attributes.underline && (style.textDecoration = "underline"), attributes.color && (style.color = attributes.color), 
                style;
            }
            function removeQuotes(text) {
                return !_.startsWith(text, "'") || StringExtensions.containsIgnoreCase(text, ",") ? text : text.slice(1, text.length - 1);
            }
            RichTextConversion.ModelKeyName = "ModelObject", RichTextConversion.TextRunElement = jsCommon.CssConstants.createClassAndSelector("textRun"), 
            RichTextConversion.convertDeltaToParagraphs = convertDeltaToParagraphs, RichTextConversion.convertParagraphsToHtml = convertParagraphsToHtml, 
            RichTextConversion.convertParagraphsToOps = convertParagraphsToOps, RichTextConversion.isValidLinkUrl = isValidLinkUrl;
        }(RichTextConversion = visuals.RichTextConversion || (visuals.RichTextConversion = {}));
        var RichText;
        !function(RichText) {
            function getCssFontFamily(font) {
                var family = fontMap[font] || font;
                return family !== RichText.defaultFont ? family : void 0;
            }
            function getFontFamilyForBuiltInFont(family) {
                var fontFamily = _.findKey(fontMap, function(value) {
                    return value === family || value.indexOf(family) > 0;
                });
                return fontFamily || family;
            }
            function getCssFontSize(fontSize) {
                return fontSize !== RichText.defaultFontSize ? fontSize : "";
            }
            var fontMap = {
                "Segoe (Bold)": visuals.Font.Family.bold.family,
                "Segoe UI": visuals.Font.Family.regular.family,
                "Segoe UI Light": visuals.Font.Family.light.family,
                Heading: visuals.Font.Family.light.family,
                Body: visuals.Font.Family.regular.family
            }, fonts = [ "Arial", "Arial Black", "Arial Unicode MS", "Calibri", "Cambria", "Cambria Math", "Candara", "Comic Sans MS", "Consolas", "Constantia", "Corbel", "Courier New", "Georgia", "Lucida Sans Unicode", "Segoe (Bold)", "Segoe UI", "Segoe UI Light", "Symbol", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana", "Wingdings" ].map(function(font) {
                return {
                    label: font,
                    value: fontMap[font] || font
                };
            });
            RichText.defaultFont = getCssFontFamily("Segoe UI Light");
            var fontSizes = [ 8, 9, 10, 10.5, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 42, 44, 54, 60, 66, 72, 80, 88, 96 ].map(function(size) {
                return {
                    label: "" + size,
                    value: size + "px"
                };
            });
            RichText.defaultFontSize = "14px";
            var defaultTextAlignmentValue = "Left", textAlignments = [ "Left", "Center", "Right" ].map(function(alignment) {
                var alignmentLowerCase = alignment.toLowerCase();
                return {
                    label: alignment,
                    value: alignment === defaultTextAlignmentValue ? "" : alignmentLowerCase,
                    glyph: "align" + alignmentLowerCase
                };
            });
            RichText.defaultFontColor = "#333333", RichText.getCssFontFamily = getCssFontFamily, 
            RichText.getFontFamilyForBuiltInFont = getFontFamilyForBuiltInFont, RichText.getCssFontSize = getCssFontSize;
            var QuillWrapper = function() {
                function QuillWrapper(readOnly, host) {
                    var _this = this;
                    this.readOnly = readOnly, this.host = host, this.textChanged = _.noop, this.$container = $("<div>"), 
                    this.localizationProvider = {
                        get: function(stringId) {
                            return _this.host.getLocalizedString(stringId);
                        },
                        getOptional: function(stringId) {
                            return _this.host.getLocalizedString(stringId);
                        }
                    }, visuals.TextboxUtil.loadQuillResources ? (this.initialized = !1, this.dependenciesLoaded = this.host.loader().require({
                        javascript: "quill",
                        css: [ "quill.core" ]
                    }).then(function(quillStatic) {
                        return _this.initializeQuill(quillStatic);
                    })) : (this.initializeQuill(window.Quill), this.dependenciesLoaded = this.host.promiseFactory().resolve());
                }
                return QuillWrapper.prototype.initializeQuill = function(quillStatic) {
                    this.quillStatic = quillStatic, this.rebuildQuillEditor(), this.initialized = !0, 
                    this.quillStatic.debug("error");
                }, QuillWrapper.prototype.getElement = function() {
                    return this.$container;
                }, QuillWrapper.prototype.getContents = function() {
                    if (this.initialized) return this.editor.getContents();
                }, QuillWrapper.prototype.setContents = function(contents) {
                    var _this = this;
                    return this.initialized ? void this.editor.setContents(contents) : void this.dependenciesLoaded.then(function() {
                        return _this.setContents(contents);
                    });
                }, QuillWrapper.prototype.resize = function(viewport) {
                    this.$container.width(viewport.width), this.$container.height(viewport.height);
                }, QuillWrapper.prototype.setReadOnly = function(readOnly) {
                    var readOnlyChanged = readOnly !== this.readOnly;
                    this.readOnly = readOnly, this.initialized && readOnlyChanged && this.rebuildQuillEditor();
                }, QuillWrapper.prototype.setSelection = function(index, length) {
                    this.editor && this.editor.setSelection(index, length);
                }, QuillWrapper.prototype.getSelection = function(focus) {
                    if (this.editor) return this.editor.getSelection(focus);
                }, QuillWrapper.prototype.focus = function() {
                    this.editor && 0 === $(document.activeElement).closest(this.$container).length && this.editor.focus();
                }, QuillWrapper.prototype.destroy = function() {
                    this.host.setToolbar(null), this.$container.remove(), this.$container = null, this.$toolbarDiv = null, 
                    this.$editorDiv = null, this.editor = null;
                }, QuillWrapper.prototype.getSelectionAtCursor = function() {
                    var text = this.getTextWithoutTrailingBreak(), selection = this.getSelection(!0);
                    if (selection && 0 === selection.length) {
                        var result = jsCommon.WordBreaker.find(selection.index, text);
                        return {
                            index: result.start,
                            length: result.end - result.start
                        };
                    }
                    return selection;
                }, QuillWrapper.prototype.getWord = function() {
                    var selection = this.getSelectionAtCursor();
                    return this.getTextWithoutTrailingBreak().slice(selection.index, selection.index + selection.length);
                }, QuillWrapper.prototype.getEditorContainer = function() {
                    if (this.editor) return $(this.editor.container);
                }, QuillWrapper.prototype.getTextWithoutTrailingBreak = function() {
                    return this.editor.getText().slice(0, -1);
                }, QuillWrapper.prototype.rebuildQuillEditor = function() {
                    var _this = this, contents = null;
                    this.editor && (contents = this.editor.getContents()), this.$container.empty(), 
                    this.$container.keydown(function(e) {
                        var which = e.which;
                        e.ctrlKey && KeyUtils.isCtrlShortcutKey(which) && e.stopPropagation(), (KeyUtils.isArrowKey(which) || KeyUtils.isNudgeModifierKey(which)) && e.stopPropagation(), 
                        KeyUtils.isDeleteKey(which) && e.stopPropagation();
                    });
                    var $editorDiv = this.$editorDiv = $("<div>"), config = {
                        readOnly: this.readOnly,
                        formats: [ "bold", "italic", "underline", "font", "size", "link", "align", "color" ],
                        modules: {
                            history: {
                                userOnly: !0
                            }
                        }
                    }, linkInputTemplate = Toolbar.buildToolbarLinkInputTemplate(this.localizationProvider), linkInputNode = Toolbar.LinkInput.buildNode(linkInputTemplate);
                    if (!this.readOnly) {
                        var $toolbarDiv = this.$toolbarDiv;
                        $toolbarDiv || (this.$toolbarDiv = $toolbarDiv = Toolbar.buildToolbar(this, this.localizationProvider, linkInputNode)), 
                        $toolbarDiv.addClass("unselectable"), this.host.setToolbar($toolbarDiv), config.modules.toolbar = {
                            container: $toolbarDiv.get(0)
                        }, $editorDiv.attr("drag-resize-disabled", "true");
                    }
                    if (this.editor = new this.quillStatic($editorDiv.get(0), config), !this.readOnly) {
                        var linkTooltip_1 = new Toolbar.LinkInput(linkInputNode, this.editor, this.quillStatic, linkInputTemplate), linkHandler = function(value) {
                            value ? (_this.editor.setSelection(_this.getSelectionAtCursor()), linkTooltip_1.open()) : linkTooltip_1.remove();
                        }, $toolbarDiv = this.$toolbarDiv, colorPicker_1 = new Toolbar.ColorPicker({
                            quill: this.editor,
                            hostServices: this.host,
                            $colorSwatch: $toolbarDiv.find(Toolbar.ColorPicker.colorSwatchGlyphClassAndSelector.selector),
                            $colorPickerButton: $toolbarDiv.find(Toolbar.ColorPicker.pickerButtonClassAndSelector.selector),
                            $colorPickerButtonWrapper: $toolbarDiv.find(Toolbar.ColorPicker.pickerButtonWrapperClassAndSelector.selector),
                            defaultColor: RichText.defaultFontColor,
                            format: "color"
                        }), colorHandler = function() {
                            return colorPicker_1.applyFormat(colorPicker_1.getColor());
                        }, parchment_1 = this.quillStatic.import("parchment"), fontFormat_1 = this.quillStatic.import("formats/font");
                        fontFormat_1.value = function(element) {
                            var key = QuillWrapper.camelize(fontFormat_1.keyName);
                            return _.escape(visuals.Font.normalizeFamily(element.style[key]));
                        }, fontFormat_1.canAdd = function(node, value) {
                            var match = parchment_1.query(node, parchment_1.Scope.BLOT & (fontFormat_1.scope | parchment_1.Scope.TYPE));
                            return null != match && (null == fontFormat_1.whitelist || fontFormat_1.whitelist.indexOf(visuals.Font.normalizeFamily(_.unescape(value))) > -1);
                        }, fontFormat_1.add = function(node, value) {
                            if (!fontFormat_1.canAdd(node, value)) return !1;
                            var key = QuillWrapper.camelize(fontFormat_1.keyName), normalizedValue = visuals.Font.normalizeFamily(_.unescape(value));
                            return node.style[key] = normalizedValue, !0;
                        };
                        var toolbar = this.editor.getModule("toolbar");
                        toolbar.addHandler("link", linkHandler), toolbar.addHandler("color", colorHandler);
                    }
                    this.$container.append($editorDiv), contents && this.setContents(contents);
                    var textChangeFunc = _.debounce(function() {
                        return _this.onTextChanged();
                    }, QuillWrapper.textChangeThrottle);
                    this.editor.on("text-change", function(change, oldDelta, source) {
                        if ("api" !== source) {
                            for (var _i = 0, _a = change.ops; _i < _a.length; _i++) {
                                var op = _a[_i];
                                if (QuillWrapper.isInsertOp(op)) {
                                    var insertion = op.insert;
                                    if (insertion && StringExtensions.containsWhitespace(insertion)) return _this.onTextChanged(), 
                                    void textChangeFunc.cancel();
                                }
                            }
                            textChangeFunc();
                        }
                    }), this.editor.root.addEventListener("blur", function(event) {
                        var target = event.relatedTarget || document.activeElement;
                        target && (QuillWrapper.willBrowserHandleFocus(target) || _this.targetIsInToolbar(target)) || _this.setSelection(null, null);
                    }, !1);
                }, QuillWrapper.willBrowserHandleFocus = function(element) {
                    return "SELECT" === element.tagName || "INPUT" === element.tagName || !!element.getAttribute("contentEditable");
                }, QuillWrapper.prototype.targetIsInToolbar = function(element) {
                    if ("A" === element.tagName || "BUTTON" === element.tagName) {
                        var $element = $(element);
                        return this.$toolbarDiv.visible() && ($element.is(this.$toolbarDiv) || $element.closest(this.$toolbarDiv).length > 0);
                    }
                    return !1;
                }, QuillWrapper.prototype.onTextChanged = function() {
                    this.textChanged();
                }, QuillWrapper.isInsertOp = function(op) {
                    var insertOp = op;
                    return null != insertOp.insert;
                }, QuillWrapper.camelize = function(name) {
                    var parts = name.split("-"), rest = _.map(parts.slice(1), function(part) {
                        return part[0].toUpperCase() + part.slice(1);
                    }).join("");
                    return parts[0] + rest;
                }, QuillWrapper.textChangeThrottle = 600, QuillWrapper;
            }();
            RichText.QuillWrapper = QuillWrapper;
            var Toolbar;
            !function(Toolbar) {
                function buildToolbar(quillWrapper, localizationProvider, linkInput) {
                    var fontSizeFormatterName = "size", fontSizeFormatPath = getFormatPath(fontSizeFormatterName);
                    updateStyleAllowList(quillWrapper.quillStatic, fontSizeFormatterName, null, fontSizeFormatPath, !0);
                    var fontFamilyFormatterName = "font", fontFamilyValues = fonts.map(function(font) {
                        return visuals.Font.normalizeFamily(font.value);
                    }), fontFamilyFormatPath = getFormatPath(fontFamilyFormatterName);
                    updateStyleAllowList(quillWrapper.quillStatic, fontFamilyFormatterName, fontFamilyValues, fontFamilyFormatPath, !0);
                    var textAlignmentFormatterName = "align", textAlignmentValues = textAlignments.map(function(textAlignment) {
                        return textAlignment.value;
                    }), textAlignmentFormatPath = getFormatPath(textAlignmentFormatterName);
                    updateAllowList(quillWrapper.quillStatic, textAlignmentFormatPath, textAlignmentValues);
                    var toolbarFonts = _.map(fonts, function(option) {
                        return {
                            label: option.label,
                            glyph: option.glyph,
                            value: _.escape(visuals.Font.normalizeFamily(option.value))
                        };
                    }), toolbarDefaultFont = _.escape(visuals.Font.normalizeFamily(RichText.defaultFont)), fontColorButtons = ColorPicker.buildFontColorButtons(localizationProvider.get("RichTextbox_FontColor_ToolTip")), $container = div().addClass("toolbar").append(formatGroup().append(picker(getTooltip("Font", localizationProvider), toolbarFonts, "font", toolbarDefaultFont, function($option, option) {
                        return $option.css("font-family", option.value), $option;
                    })).append(picker(getTooltip("Size", localizationProvider), fontSizes, "size", RichText.defaultFontSize)).append(fontColorButtons)).append(formatGroup().append(formatButton(getTooltip("Bold", localizationProvider), "bold")).append(formatButton(getTooltip("Italic", localizationProvider), "italic")).append(formatButton(getTooltip("Underline", localizationProvider), "underline"))).append(formatGroup().append(toggleGroup("Text Alignment", textAlignments, "align", defaultTextAlignmentValue, localizationProvider))).append(formatGroup().append(formatButton(getTooltip("Link", localizationProvider), "link")).append(linkInput));
                    return $container;
                }
                function getFormatPath(formatName) {
                    return "formats/" + formatName;
                }
                function updateStyleAllowList(quillStatic, attributorName, newAllowList, destinationPath, overwrite) {
                    void 0 === overwrite && (overwrite = !1), updateAllowList(quillStatic, "attributors/style/" + attributorName, newAllowList, destinationPath, overwrite);
                }
                function updateAllowList(quillStatic, attributorPath, newAllowList, destinationPath, overwrite) {
                    void 0 === overwrite && (overwrite = !1);
                    var attributor = quillStatic.import(attributorPath);
                    attributor.whitelist = newAllowList, quillStatic.register(destinationPath || attributorPath, attributor, overwrite);
                }
                function linkTooltipTemplateGenerator(removeText, doneText, editText) {
                    return $('\n                        <a href="#" class="ql-preview" target="_blank"></a>\n                        <input class="input" type="text">\n                        <span class="bar">&nbsp;|&nbsp;</span>\n                        <a class="ql-action ql-save">' + doneText + '</a>\n                        <a class="ql-action ql-edit">' + editText + '</a>\n                        <a class="ql-remove">' + removeText + "</a>\n                    ");
                }
                function buildToolbarLinkInputTemplate(localizationProvider) {
                    var template = div(), doneText = localizationProvider.get("RichTextbox_Link_Done"), removeText = localizationProvider.get("RichTextbox_Link_Remove"), editText = localizationProvider.get("RichTextbox_Link_Edit");
                    return template.append(linkTooltipTemplateGenerator(removeText, doneText, editText)), 
                    template.html();
                }
                function formatGroup() {
                    return span().addClass("ql-formats");
                }
                function div() {
                    return $("<div>");
                }
                function span() {
                    return $("<span>");
                }
                function button() {
                    return $("<button>");
                }
                function toggleGroup(title, list, format, defaultValue, localizationProvider) {
                    var $buttons = list.map(function(option) {
                        var glyph = null != option.glyph ? option.glyph : format + option.value, $button = formatButton(getTooltip(option.label, localizationProvider), format, option.value, glyph);
                        return $button;
                    });
                    return $buttons;
                }
                function picker(tooltip, list, format, defaultValue, optionModifier) {
                    var $selector = selector(tooltip, list, defaultValue, optionModifier).addClass("ql-" + format + " ql-picker");
                    return $selector;
                }
                function selector(tooltip, list, defaultValue, optionModifier) {
                    for (var $selector = $("<select>").attr("title", tooltip), _i = 0, list_1 = list; _i < list_1.length; _i++) {
                        var option = list_1[_i], $option = $("<option>").text(option.label);
                        option.value === defaultValue ? $option.attr("selected", "selected") : $option.attr("value", option.value), 
                        void 0 !== optionModifier && ($option = optionModifier($option, option)), $selector.append($option);
                    }
                    return $selector;
                }
                function formatButton(tooltip, format, value, glyph) {
                    var $button = button();
                    return null != tooltip && $button.attr("title", tooltip), null != format && $button.addClass("ql-" + format), 
                    null != value && $button.attr("value", value), null == glyph && (null != format && (glyph = format), 
                    null != value && (glyph = (glyph || "") + value)), null != glyph && $button.addClass("powervisuals-glyph " + glyph), 
                    $button;
                }
                function getTooltip(name, localizationProvider) {
                    return localizationProvider.get("RichTextbox_" + name + "_ToolTip");
                }
                Toolbar.selectors = {
                    linkTooltip: createClassAndSelector("ql-link-tooltip"),
                    toolbarUrlInput: createClassAndSelector("toolbar-url-input")
                }, Toolbar.buildToolbar = buildToolbar, Toolbar.buildToolbarLinkInputTemplate = buildToolbarLinkInputTemplate;
                var LinkInput = function() {
                    function LinkInput(container, quill, quillStatic, template) {
                        var _this = this;
                        this.$container = container, this.quill = quill, this.quillStatic = quillStatic, 
                        this.$preview = this.$container.find("a.ql-preview"), this.$textbox = this.$container.find("input[type=text]"), 
                        this.textbox = this.$textbox[0], this.$action = this.$container.find("a.ql-action"), 
                        this.hide(), this.$textbox.on("keydown", function(event) {
                            13 === event.keyCode ? (_this.save(), event.preventDefault()) : 27 === event.keyCode && (_this.hide(), 
                            event.preventDefault());
                        }), [ "mousedown", "touchstart" ].forEach(function(name) {
                            _this.$action.on(name, function(event) {
                                _this.$container.hasClass(LinkInput.editingClass) ? (_this.save(), event.preventDefault()) : (_this.edit(), 
                                event.preventDefault());
                            }), _this.$container.find("a.ql-remove").on(name, function(event) {
                                _this.remove(), event.preventDefault();
                            });
                        }), quill.on("selection-change", function(range) {
                            if (null != range || !$(document.activeElement).is(_this.$textbox)) {
                                if (null != range && 0 === range.length) {
                                    var offset = void 0;
                                    if (_a = quill.scroll.descendant(_this.quillStatic.import("formats/link"), range.index), 
                                    _this.link = _a[0], offset = _a[1], null != _this.link) return _this.range = {
                                        index: range.index - offset,
                                        length: _this.link.length()
                                    }, _this.show();
                                }
                                _this.hide();
                                var _a;
                            }
                        });
                    }
                    return LinkInput.buildNode = function(template) {
                        return div().addClass(Toolbar.selectors.toolbarUrlInput.class).append($(template));
                    }, LinkInput.prototype.edit = function() {
                        this.$container.addClass(LinkInput.editingClass), this.$textbox.focus(), this.textbox.setSelectionRange(0, this.textbox.value.length);
                    }, LinkInput.prototype.open = function() {
                        this.range = this.quill.getSelection(), this.show(), this.edit();
                    }, LinkInput.prototype.hide = function() {
                        this.range = this.link = null, this.$container.hide();
                    }, LinkInput.prototype.remove = function() {
                        this.range = this.range || this.quill.getSelection(), this.quill.formatText(this.range, "link", !1, "user"), 
                        this.quill.setSelection(this.range, "silent"), this.hide();
                    }, LinkInput.prototype.save = function() {
                        var url = this.textbox.value;
                        0 === this.range.length && (this.quill.insertText(this.range.index, url), this.quill.setSelection(this.range.index, url.length), 
                        this.range = this.quill.getSelection()), this.quill.formatText(this.range.index, this.range.length, "link", url, "user"), 
                        this.quill.setSelection(this.range, "silent"), this.link = this.quill.scroll.descendant(this.quillStatic.import("formats/link"), this.range.index)[0], 
                        this.show();
                    }, LinkInput.prototype.show = function() {
                        this.$container.removeClass(LinkInput.editingClass), this.$container.show();
                        var preview, range = this.range = this.range || this.quill.getSelection();
                        null != this.link ? preview = this.link.formats().link : (preview = this.quill.getText(range.index, range.length), 
                        preview = TextboxHelpers.LinkPreview.format(preview)), this.$textbox.val(preview), 
                        this.$preview.text(preview), this.$preview.attr("href", preview);
                    }, LinkInput.editingClass = "ql-editing", LinkInput;
                }();
                Toolbar.LinkInput = LinkInput;
                var ColorPicker = function() {
                    function ColorPicker(options) {
                        var _this = this;
                        this.quill = options.quill, this.hostServices = options.hostServices, this.$colorSwatch = options.$colorSwatch, 
                        this.$colorPickerButtonWrapper = options.$colorPickerButtonWrapper, this.defaultColor = options.defaultColor, 
                        this.format = options.format, this.promiseFactory = this.hostServices.promiseFactory(), 
                        this.currentColor = options.defaultColor, this.setSwatch(this.currentColor), options.$colorPickerButton.on("click", function() {
                            return _this.toggle();
                        });
                    }
                    return ColorPicker.buildFontColorButtons = function(tooltip) {
                        var fontColorGlyph = $("<span/>").addClass("powervisuals-glyph").addClass(ColorPicker.colorGlyphClassAndSelector.class), fontColorSwatch = $("<span/>").addClass("powervisuals-glyph").addClass(ColorPicker.colorSwatchGlyphClassAndSelector.class), fontColorButton = $("<button>").addClass("ql-color").addClass(ColorPicker.colorButtonClassAndSelector.class).attr("title", tooltip).val("false").append(fontColorGlyph).append(fontColorSwatch), fontColorPickerButton = $("<button>").addClass("colorpicker powervisuals-glyph chevrondown").addClass(ColorPicker.pickerButtonClassAndSelector.class).val("false"), fontColorPickerWrapper = $("<div>").addClass(ColorPicker.pickerButtonWrapperClassAndSelector.class).append(fontColorPickerButton);
                        return [ fontColorButton, fontColorPickerWrapper ];
                    }, ColorPicker.prototype.onColorChange = function(newColor) {
                        this.setSwatch(newColor ? newColor : this.defaultColor), this.applyFormat(newColor ? newColor : null), 
                        this.currentColor = newColor;
                    }, ColorPicker.prototype.getColor = function() {
                        return this.currentColor;
                    }, ColorPicker.prototype.applyFormat = function(color) {
                        color ? this.quill.format(this.format, color, "user") : this.quill.format(this.format, !1, "user");
                    }, ColorPicker.prototype.toggle = function() {
                        this.getColorPicker().then(function(colorPicker) {
                            return colorPicker.toggle();
                        });
                    }, ColorPicker.prototype.getColorPicker = function() {
                        var defer, _this = this;
                        if (!this.colorPicker && this.existingDeferred) defer = this.existingDeferred; else if (defer = this.promiseFactory.defer(), 
                        this.colorPicker) defer.resolve(this.colorPicker); else {
                            this.existingDeferred = defer;
                            var element = this.$colorPickerButtonWrapper.get(0);
                            this.hostServices.getUIComponentFactory().createColorPicker(element, this.defaultColor, function(newColor) {
                                return _this.onColorChange(newColor);
                            }).then(function(colorPicker) {
                                _this.colorPicker = colorPicker, defer.resolve(colorPicker);
                            });
                        }
                        return defer.promise;
                    }, ColorPicker.prototype.setSwatch = function(color) {
                        this.$colorSwatch.css("color", color);
                    }, ColorPicker.colorGlyphClassAndSelector = createClassAndSelector("fontcolor"), 
                    ColorPicker.colorSwatchGlyphClassAndSelector = createClassAndSelector("fontcolorswatch"), 
                    ColorPicker.colorButtonClassAndSelector = createClassAndSelector("fontcolorbutton"), 
                    ColorPicker.pickerButtonClassAndSelector = createClassAndSelector("fontcolorpicker"), 
                    ColorPicker.pickerButtonWrapperClassAndSelector = createClassAndSelector("fontcolorbutton-wrapper"), 
                    ColorPicker;
                }();
                Toolbar.ColorPicker = ColorPicker;
            }(Toolbar || (Toolbar = {}));
        }(RichText = visuals.RichText || (visuals.RichText = {}));
    }(visuals = powerbi.visuals || (powerbi.visuals = {}));
}(powerbi || (powerbi = {})), define("TextboxVisual/textboxModule", [ "require", "exports" ], function(require, exports) {
    function createTextbox(options) {
        return new powerbi.visuals.Textbox(options);
    }
    function createTextboxViewModelAdapter(smallViewportProperties) {
        return new powerbi.visuals.TextboxHelpers.ViewModelAdapter(smallViewportProperties);
    }
    function createAlwaysUseSmallViewportTextboxViewModelAdapter() {
        return new powerbi.visuals.TextboxHelpers.AlwaysUseSmallViewport();
    }
    Object.defineProperty(exports, "__esModule", {
        value: !0
    }), exports.createTextbox = createTextbox, exports.createTextboxViewModelAdapter = createTextboxViewModelAdapter, 
    exports.createAlwaysUseSmallViewportTextboxViewModelAdapter = createAlwaysUseSmallViewportTextboxViewModelAdapter;
});